/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.model.geo;

import java.awt.Color;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.io.Serializable;

public class GLine extends Line2D.Double implements Serializable {
    
	private static final long serialVersionUID = 1L;
    private GPoint p1;
    private GPoint p2;
    private int label = 0;
    private int nParts = 1;
	private Color color = Color.black;
	private GPoint[] discrete;
	private boolean isFrame = true;
	
//*****************************************************************************
	
    public GLine() {
        this(0, 0, 0, 0);
    }
    
//*****************************************************************************
	
    public GLine(double x1, double y1, double x2, double y2) {
		this(new GPoint(x1, y1), new GPoint(x2, y2));
    }
    
//*****************************************************************************
	
    public GLine(GPoint p1, GPoint p2) {
        this.p1 = p1;
        this.p2 = p2;
		this.discrete();
    }
    
//*****************************************************************************
	
    public Point2D getP1() {
        return p1;
    }
    
//*****************************************************************************
	
    public Point2D getP2() {
        return p2;
    }
    
//*****************************************************************************
	
    public double getX1() {
        return p1.getX();
    }
    
//*****************************************************************************
	
    public double getY1() {
        return p1.getY();
    }
    
//*****************************************************************************
	
    public double getX2() {
        return p2.getX();
    }
    
//*****************************************************************************
	
    public double getY2() {
        return p2.getY();
    }
    
//*****************************************************************************
	
    public boolean equals(Object obj) {
        
        if (obj instanceof Line2D) {
            Line2D li = (Line2D)obj;
            if ((li.getP1().equals(this.getP1())) && (li.getP2().equals(this.getP2()))) {
                return true;
            }
        }
        
        return false;
    }
	
//*****************************************************************************
	
	public void setLabel(int lb) {
		this.label = lb;
	}
	
//*****************************************************************************
	
	public int getLabel( ) {
		return label;
	}
	
//*****************************************************************************
	
	public void setNParts(int np) {
		this.nParts = np;
        this.discrete();
	}
	
//*****************************************************************************
	
	public int getNParts( ) {
		return nParts;
	}
	
//*****************************************************************************
	
	public void setDiscrete(GPoint[] discret) {
		this.discrete = (GPoint[])discret.clone();
	}
	
//*****************************************************************************
	
	private void discrete( ) {
		double nx;
		double ny;
		double t;
		discrete = new GPoint[nParts+1];
		for (int count = 0; count <= nParts; count++) {
			t = (double)count/nParts;
			nx = (1-t)*getX1() + (t)*getX2();
			ny = (1-t)*getY1() + (t)*getY2();
			discrete[count] = new GPoint(nx,ny);
		}
	}
	
//*****************************************************************************
	
	public GPoint[] getDiscrete( ) {
		return discrete;
	}
	
//*****************************************************************************
	
    public void setColor(Color c) {
        this.color = c;
    }
	
//*****************************************************************************
	
    public Color getColor( ) {
        return color;
    }
	
//*****************************************************************************
	
    public double getAngle( ) {
		double angle = Math.atan2( (getY2()-getY1()), (getX2()-getX1()) );
		return angle;
    }
	
//*****************************************************************************
	
	public void setIsFrame(boolean a){
		isFrame = a;
	}
	
//*****************************************************************************
	
	public boolean isFrame(){
		return isFrame;
	}
	
//*****************************************************************************
}

